package com.cheng.io.print;

import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 打印流（字符形式）
 * 需要手动刷新流
 * 对于PrintStream多了个支持使用FileWriter的构造方法
 * PrintWriter (Writer out)
 * PrintWriter(OutputStream out)
 * PrintWriter(OutputStream out, boolean autoFlush)
 */
public class PrintWriterTest01 {
    public static void main(String[] args) {
        try (
                PrintWriter writer = new PrintWriter(new FileWriter("io/resources/log2"));
                // PrintWriter(OutputStream out, boolean autoFlush) 支持自动刷新流
                // PrintWriter writer = new PrintWriter(new FileOutputStream("io/resources/log2"),true);
        ) {
            writer.println("Hello World!");
            writer.println("Hello World!");

            writer.flush();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
